package com.xue566.controller;

import com.xue566.config.LogPointer;
import com.xue566.entity.BaseEntity;
import com.xue566.entity.SchoolEntity;
import com.xue566.service.ISchoolService;
import com.xue566.util.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 22:08 2020/8/17
 * @return
 */
@RequestMapping("school/client")
@RestController
@Slf4j
@CrossOrigin(value = "*", maxAge = 3600)
public class SchoolController {

    @Resource
    private ISchoolService iSchoolService;

    @LogPointer(value = "学校客户端日志")
    @RequestMapping("queryList")
    public ResultBody<SchoolEntity> queryList (@RequestBody SchoolEntity schoolEntity) {
        schoolEntity.setTrackId(UUID.randomUUID().toString());
        schoolEntity.setIsUsed(1);
        ResultBody<SchoolEntity> schoolEntitys = iSchoolService.queryList(schoolEntity);
        log.info("学校列表客户端 - [{} - {}]", schoolEntity, schoolEntitys.getQueryList());
        return iSchoolService.queryList(schoolEntity);
    }

    @RequestMapping("/save")
    public ResultBody<SchoolEntity> saveSchool () {
        BaseEntity baseEntity = new SchoolEntity();
        ResultBody<SchoolEntity> schoolEntity = iSchoolService.saveSchool(baseEntity);
        log.info("新增学校记录 - [{},{}]", baseEntity, schoolEntity);
        return schoolEntity;
    }


    @GetMapping("/selectSchool/{schoolId}")
    public ResultBody<SchoolEntity> selectSchool (@PathVariable String schoolId) {
        SchoolEntity baseEntity = new SchoolEntity();
        baseEntity.setTrackId(UUID.randomUUID().toString());
        baseEntity.setSchoolId(schoolId);
        ResultBody<SchoolEntity> schoolEntity = iSchoolService.selectSchool(baseEntity);
        log.info("查询学校记录 - [{} - {}]", baseEntity, schoolEntity);
        return schoolEntity;
    }


    @RequestMapping("/updateSchool")
    public ResultBody<SchoolEntity> updateSchool () {
        SchoolEntity schoolEntity = new SchoolEntity();
        schoolEntity.setTrackId(UUID.randomUUID().toString());
        schoolEntity.setSchoolId("00000");
        schoolEntity.setCenterId("12");
        schoolEntity.setCreateTime(new SimpleDateFormat().format(new Date()));
        schoolEntity.setIsUsed(2);
        schoolEntity.setSchoolAddress("安徽省合肥市高新区玉兰大道");
        schoolEntity.setSchoolName("合肥33333333333333333八中");
        schoolEntity.setLife(3);
        schoolEntity.setType(11);
        schoolEntity.setUserId("22333");
        ResultBody<SchoolEntity> schoolEntitys = iSchoolService.updateSchool(schoolEntity);
        log.info("更新学校记录 - [{} - {}]", schoolEntity, schoolEntitys);
        return schoolEntitys;
    }


    @RequestMapping(value = "/deleteSchool/{id}", method = RequestMethod.DELETE)
    public ResultBody<SchoolEntity> deleteSchool (@PathVariable String schoolId) {
        log.info("根据schoolId删除学校记录 - {}", schoolId);
        SchoolEntity schoolEntity = new SchoolEntity();
        schoolEntity.setSchoolId(schoolId);
        ResultBody<SchoolEntity> schoolEntitys = iSchoolService.deleteSchool(schoolEntity);
        return schoolEntitys;
    }
}
